package com.testmanager.testmananger.quantitative.web;

import com.testmanager.testmananger.quantitative.domain.ProjectInfoEntity;
import com.testmanager.testmananger.quantitative.dto.*;
import com.testmanager.testmananger.quantitative.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;

@RestController
@RequestMapping("/manager")
public class IterationResource {

    @Autowired
    BugInfoService bugInfoService;
    @Autowired
    TestInfoService testInfoService;
    @Autowired
    TaskInfoService taskInfoService;
    @Autowired
    DevelopInfoService developInfoService;
    @Autowired
    DemandInfoService demandInfoService;
    @Autowired
    ProjectInfoService projectInfoService;
    @Autowired
    IterationInfoService iterationInfoService;

    @GetMapping("/getBugs/{iterationId}")
    public List<BugInfoDto> getBuginfoDtos(@PathVariable("iterationId") Long iterationId){
        return bugInfoService.getBugsByItertionId(iterationId);
    }

    @PostMapping("/saveBugs/{iterationId}")
    public List<BugInfoDto> saveBuginfoDtos(@PathVariable("iterationId") Long iterationId,@RequestBody BugInfoDto bugInfoDto){
        return  bugInfoService.saveBugsByItertionId(bugInfoDto,iterationId);
    }

    @GetMapping("/getTestInfo/{iterationId}")
    public TestInfoDto getTestInfo(@PathVariable("iterationId") Long iterationId){
        return testInfoService.getTestInfoWithTaskInfo(iterationId);
    }
    @PostMapping("/saveTestInfo/{iterationId}")
    public TestInfoDto saveTestInfo(@PathVariable("iterationId")Long iterationId,@RequestBody TestInfoDto testInfoDto){
        return testInfoService.saveTestInfoWithoutTaskInfo(iterationId, testInfoDto);
    }

    @PostMapping("saveTaskInfo/{ownerNo}")
    public List<TaskInfoDto> saveTaskInfo(@PathVariable("ownerNo")Long testno,@RequestBody TaskInfoDto taskInfoDto){
        return  taskInfoService.saveTaskInfoDto(testno, taskInfoDto);
    }
    @PostMapping("saveTaskInfos/{ownerNo}")
    public List<TaskInfoDto> saveTaskInfo(@PathVariable("ownerNo")Long testno,@RequestBody List<TaskInfoDto> taskInfoDtos){
        return  taskInfoService.saveTaskInfoDtos(testno, taskInfoDtos);
    }
    @GetMapping("getTaskInfos/{ownerNo}")
    public List<TaskInfoDto> getTaskInfo(@PathVariable("ownerNo")Long ownno){
        return  taskInfoService.getTaskInfoDtos(ownno);
    }
    @PostMapping("deleteTaskInfo/{taskId}")
    public void deleteTask(@PathVariable("taskId" )  long id){
            taskInfoService.deleteTask(id);
    }


    @GetMapping("/getDevelopInfo/{iterationId}")
    public DevelopInfoDto getDevelopInfo(@PathVariable("iterationId")Long iterationId){
        return developInfoService.getDevelopInfoWithTaskInfo(iterationId);
    }
    @PostMapping("/saveDevelopInfo/{iterationId}")
    public DevelopInfoDto saveDevelopInfo(@PathVariable("iterationId")Long iterationId,@RequestBody DevelopInfoDto developInfoDto)
    {return developInfoService.saveDevelopInfoWithoutTaskInfo(iterationId, developInfoDto);}

    @GetMapping("/getDemandInfo/{iterationId}")
    public DemandInfoDto getDemandInfo(@PathVariable("iterationId")Long iterationId){
        return demandInfoService.getDemandInfo(iterationId);
    }

    @PostMapping("/saveDemandInfo/{iterationId}")
    public DemandInfoDto getDemandInfo(@PathVariable("iterationId")Long iterationId,@RequestBody DemandInfoDto demandInfoDto){
        return demandInfoService.saveDemandInfo(iterationId, demandInfoDto);
    }

    @GetMapping("/getProjects")
    public List<ProjectInfoEntity> getProjectsInfo(){
        return projectInfoService.getAllProjectInfo();
    }

    @PostMapping("/saveProject")
    public List<ProjectInfoEntity> saveProjectsInfo(@RequestBody ProjectInfoEntity projectInfoEntity){
        return projectInfoService.saveProjectInfo(projectInfoEntity);
    }
    @PostMapping("/searchInteration")
        public PageableDto searchIntertion(@RequestBody IterationSearchDto iterationSearchDto){
        return iterationInfoService.findIterationPage(iterationSearchDto);
    }
    @GetMapping("getInteration")
    public PageableDto getInteration(){
        return iterationInfoService.getIterationPage();
    }

    @GetMapping("getInterationDetail/{id}")
    public IterationInfoDto getInterationByID(@PathVariable("id")long id){
        return iterationInfoService.getIterationDtoDetail(id);
    }
    @PostMapping("saveIteration")
    public PageableDto saveIteration(@RequestBody IterationInfoDto iterationInfoDto){
        return iterationInfoService.saveIteration(iterationInfoDto);
    }

    @PostMapping("iterationChange/{iterationId}")
    public boolean saveIterationChangeRecord(@PathVariable("iterationId")Long iterationId,@RequestParam("fromStatus")int fromStatus,@RequestParam("toStatus")int toStatus){
        return iterationInfoService.saveIterationStatusChangeRecord(iterationId,fromStatus, toStatus);

    }


}
